package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.service.IStrategyThemeService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.query.StrategyQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyDetail")
public class StrategyDetailController {
    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyCatalogService strategyCatalogService;
    @Reference
    private IStrategyThemeService strategyThemeService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyQueryObject qo, Model model) {
        model.addAttribute("pageInfo", strategyDetailService.query(qo));
        return "strategyDetail/list";
    }

    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("entity", strategyDetailService.get(id));
            //共享该文章的标签
            model.addAttribute("tags", strategyDetailService.getTags(id));
        }
        model.addAttribute("catalogs", strategyCatalogService.list());
        model.addAttribute("themes", strategyThemeService.list());
        return "strategyDetail/input";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail entity, String tags) {
        strategyDetailService.saveOrUpdate(entity, tags);
        return new AjaxResult();
    }
}
